package com.stars.empoly.activity

import android.text.Editable
import android.text.TextWatcher
import com.stars.empoly.base.MBActivity
import com.stars.empoly.databinding.ActivitySetUpBinding
import com.stars.empoly.vmodel.SetUpVModel

/**
 *on 2022/9/23
 */
class SetUpActivity: MBActivity<SetUpVModel, ActivitySetUpBinding>() {


    private val num = 500


    //用这个
//    var adapter: SetUpAdapter? = null


    override fun listeners() {
        super.listeners()

        binding.etMark.addTextChangedListener(object : TextWatcher {
            private var wordNum //记录输入的字数
                    : CharSequence? = null
            private var selectionStart = 0
            private var selectionEnd = 0
            override fun beforeTextChanged(charSequence: CharSequence, i: Int, i1: Int, i2: Int) {}
            override fun onTextChanged(s: CharSequence, i: Int, i1: Int, i2: Int) {
                wordNum = s //实时记录输入的字数
            }

            override fun afterTextChanged(s: Editable) {
                val number = s.length

                //TextView显示剩余字数
                binding.tvNumber.text = "$number/$num"
                selectionStart = binding.etMark.selectionStart
                selectionEnd = binding.etMark.selectionEnd
                if (wordNum!!.length > num) {
                    //删除多余输入的字（不会显示出来）
                    s.delete(selectionStart - 1, selectionEnd)
                    val tempSelection = selectionEnd
                    binding.etMark.text = s
                    binding.etMark.setSelection(tempSelection) //设置光标在最后
                }
            }
        })


    }

    override fun vmClass(): Class<SetUpVModel> {
        return SetUpVModel::class.java
    }
    override fun binding(): ActivitySetUpBinding {
       return ActivitySetUpBinding.inflate(layoutInflater)
    }

    override fun title(): String? {
        return "服务设置内容"
    }
}
